//
//  LQYTopCell.m
//  基本框架
//
//  Created by runone02 on 2018/6/27.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "LQYTopCell.h"


NSString *const nameLabel = @"nameLabel";
NSString *const icon = @"icon";
NSString *const firmNameLabel = @"firmNameLabel";
NSString *const authenticationBtn = @"authenticationBtn";
NSString *const medalBtn = @"medalBtn";
NSString *const stateBtn = @"stateBtn";

@implementation LQYTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.text = @"名字";
    self.nameLabel.textColor = [UIColor blackColor];
    [self addSubview:self.nameLabel];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(W_RATIO(15));
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(SCREEN_WIDTH/4);
    }];
    
    self.QRCodeBtn = [[UIButton alloc]init];
    [self.QRCodeBtn setImage:IMAGE(@"qr_code") forState:UIControlStateNormal];
    [self addSubview:self.QRCodeBtn];
    
    [self.QRCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.nameLabel);
        make.left.mas_equalTo(self.nameLabel.mas_right).with.offset(10);

    }];
    
    self.icon = [[UIButton alloc]init];
    [self.icon setImage:IMAGE(@"IMPersonMoren") forState:UIControlStateNormal];
    [self addSubview: self.icon];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.QRCodeBtn);
        make.right.mas_equalTo(self).with.offset(-20);
    }];
    
    self.authenticationBtn = [[UIButton alloc]init];
    [self.authenticationBtn setTitle:@"高级认证" forState:UIControlStateNormal];
    [self.authenticationBtn setImage:IMAGE(@"safe") forState:UIControlStateNormal];
    self.authenticationBtn.titleLabel.font = TITLE_FONT(28);
    [self.authenticationBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self addSubview:self.authenticationBtn];
    
    [self.authenticationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo (self.nameLabel.mas_bottom).with.offset(40);
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDTH/3);
    }];
    
    self.firmNameLabel = [[UILabel alloc]init];
    self.firmNameLabel.text = @"公司名";
    self.firmNameLabel.textColor = [UIColor blackColor];
    [self addSubview:self.firmNameLabel];
    
    [self.firmNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.authenticationBtn);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(self.authenticationBtn.mas_left).with.offset(-20);
    }];
    
    self.medalBtn = [[UIButton alloc]init];
    [self.medalBtn setTitle:@" 勋章" forState:UIControlStateNormal];
    self.medalBtn.titleLabel.font = TITLE_FONT(30);
    [self.medalBtn setImage:IMAGE(@"safe") forState:UIControlStateNormal];
    [self.medalBtn setBackgroundColor:RGB(239, 188, 56)];
    self.medalBtn.layer.borderWidth = 2.0f;
    self.medalBtn.layer.borderColor = [UIColor orangeColor].CGColor;
    self.medalBtn.layer.cornerRadius = W_RATIO(30);
    self.medalBtn.clipsToBounds = YES;

    [self.medalBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:self.medalBtn];
    
    [self.medalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.authenticationBtn);
        make.right.mas_equalTo(self).with.offset(-10);
        make.left.mas_equalTo(self.authenticationBtn.mas_right).with.offset(20);
        make.height.mas_equalTo(W_RATIO(55));
    }];
    
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview: self.lineView];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.firmNameLabel.mas_bottom).with.offset(20);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(1);
    }];
    
    self.stateBtn = [[UIButton alloc]init];
    [self.stateBtn setTitle:@"添加工作状态...." forState:UIControlStateNormal];
    self.stateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.stateBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    self.stateBtn.titleLabel.font = TITLE_FONT(28);
    [self.stateBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self addSubview:self.stateBtn];
    [self.stateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).with.offset(10);
        make.left.mas_equalTo(self.lineView);
        make.right.mas_equalTo(-10);
    }];
}

- (void)setContentData:(NSDictionary *)dic {
    [self.icon setImage:IMAGE([dic valueForKey:icon]) forState:UIControlStateNormal];
    self.nameLabel.text = [dic valueForKey:nameLabel];
    self.firmNameLabel.text = [dic valueForKey:firmNameLabel];
    [self.authenticationBtn setTitle:[dic valueForKey:authenticationBtn] forState:UIControlStateNormal];
    [self.medalBtn setTitle:[dic valueForKey:medalBtn] forState:UIControlStateNormal];
    [self.stateBtn setTitle:[dic valueForKey:stateBtn] forState:UIControlStateNormal];
}

@end
